package com.zhengjiang.newdate;

import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.util.concurrent.TimeUnit;

/**
 * @author zhengjiang
 * @version 1.0.0
 * @description java8 日期、时间包
 * @date 2021/5/31
 **/
public class NewDatePackageTest {

    public static void main(String[] args) {
        Clock clock = Clock.system(ZoneId.of("Asia/Shanghai"));
        Instant instant = Instant.now().plusMillis(TimeUnit.HOURS.toMillis(8));
        System.out.println("当前日期:" + instant);

        long millis = clock.millis();
        long currentMillis = System.currentTimeMillis();
        System.out.println(millis);
        System.out.println(currentMillis);

        getDuration(600060);

    }

    public static void getDuration(long seconds){
        Duration duration = Duration.ofSeconds(seconds);
        long minutes = duration.toMinutes();
        System.out.println( seconds + "秒=" + minutes + "分");
        long hours = duration.toHours();
        System.out.println( seconds + "秒=" + hours + "小时");
        long days = duration.toDays();
        System.out.println( seconds + "秒=" + days + "天");

        Duration hd = Duration.ofDays(days);
        long dayToHours = hd.toHours();
        long leftHours = hours - dayToHours;

        Duration hh = Duration.ofHours(hours);
        long hoursToMinutes = hh.toMinutes();
        long leftMinutes = minutes - hoursToMinutes;

        long leftSeconds = seconds - minutes * 60;
        System.out.println(seconds + "秒=" + days + "天" + leftHours +"小时" + leftMinutes +"分"+ leftSeconds+"秒");
    }








}
